/*
 * Phase.cpp
 *
 *  Created on: 23 May 2011
 *      Author: allan
 */

#include "Phase.h"

// C++ includes
#include <numeric>

Phase::Phase()
{}

Phase::~Phase()
{}

void Phase::AddSpecies(string nameOfSpecies)
{
	species.push_back(nameOfSpecies);
	
	moles.push_back(0.0);
}

void Phase::SetName(string nameOfPhase)
{
	this->nameOfPhase = nameOfPhase;
}

void Phase::SetMolesOfSpecies(unsigned iSpecies, double value)
{
	totalNumberMoles -= moles[iSpecies];
			
	moles[iSpecies] = value;
	
	totalNumberMoles += moles[iSpecies];
}

void Phase::SetMolesOfSpecies(const vector<double>& moles)
{
	this->moles = moles;
	
	totalNumberMoles = accumulate(moles.begin(), moles.end(), 0.0);
}

const string Phase::GetName() const
{
	return nameOfPhase;
}

const unsigned Phase::GetNumOfSpecies() const
{
	return species.size();
}

const unsigned Phase::GetIndexOfSpecies(string nameOfSpecies) const
{
	for(unsigned iSpecies = 0; iSpecies < GetNumOfSpecies(); ++iSpecies)
		if(species[iSpecies] == nameOfSpecies)
			return iSpecies;
	
	return unsigned(-1);
}

const string Phase::GetNameOfSpecies(unsigned iSpecies) const
{
	return species[iSpecies];
}

const double Phase::GetMolesOfSpecies(unsigned iSpecies) const
{
	return moles[iSpecies];
}

const double Phase::GetMolarFractionOfSpecies(unsigned iSpecies) const
{
	return moles[iSpecies]/totalNumberMoles;
}

const double Phase::GetTotalNumberOfMoles() const
{
	return totalNumberMoles;
}

